﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LEARNREN.COM.UI;
using LEARNREN.COM.Entity;
using LEARNREN.COM.BLL;

namespace LEARNREN.COM.WebSite
{
    public partial class ShowFeedBack : BasePage
    {
        protected Catalogue curCatalogue = null;
        protected IEnumerable<Catalogue> childCatalogueList = null;
        protected Message curMessage = null;

        private MessageLogic messageLogic = null;
        private CatalogueLogic catalogueLogic = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            Initialize();
            InitializeCtrl();
        }

        private void Initialize()
        {
            string sid = Request.QueryString["id"];
            long id = 0;
            if (long.TryParse(sid, out id))
            {
                curMessage = messageLogic.GetById(id);
                if (curMessage == null)
                {
                    Response.Redirect("~/");
                }

                curCatalogue = catalogueLogic.GetByIdFromCache( curMessage.CatalogueId);
                if (curCatalogue == null)
                {
                    Response.Redirect("~/");
                }

                childCatalogueList = catalogueLogic.GetChildren(curCatalogue.Id);
            }
            else
            {
                Response.Redirect("~/");
            }
        }

        private void InitializeCtrl()
        {
            LiteralMsgTitle.Text = curMessage.MsgTitle;
            LiteralMsgCreateDate.Text = curMessage.CreatedTime.ToLongDateString();
            LiteralMsgContent.Text = curMessage.MsgContent;

            if (curMessage.MsgHasRe == false)
            {
                LiteralMsgRe.Text = "尚未回复";
            }
            else
            {
                LiteralMsgRe.Text = curMessage.MsgRe;
                LiteralMsgReDate.Text = curMessage.MsgReDate.ToLongDateString();
            }
        }

        protected override void InitLogic()
        {
            messageLogic = new MessageLogic();
            catalogueLogic = new CatalogueLogic();
        }

        protected override void DisposeLogic()
        {
            if (messageLogic != null)
            {
                messageLogic.Dispose();
                messageLogic = null;
            }

            if (catalogueLogic != null)
            {
                catalogueLogic.Dispose();
                catalogueLogic = null;
            }
        }
    }
}